#pragma once

#include <boost/shared_ptr.hpp>

#include "exports.hpp"




/**
 * This is the basic interface every plugin must implement.
 *
 * Plugins can extend the crawler in many ways, for example offering filtering
 * and data processing on an infinite amount of data.
 * Every plugin must implement these functions, so that the crawler has control
 * over the plugin. 
 */
class CRAWLER_API Plugin
{
public:

	typedef boost::shared_ptr<Plugin>         Ptr;
	typedef boost::shared_ptr<const Plugin>   const_Ptr;

private:

	volatile bool   m_enabled;
	volatile bool   m_paused;
	std::size_t     m_numExceptions;

public:

	Plugin();
	virtual ~Plugin();



	/**
	 * Get the name of the plugin.
	 */
	virtual QString name() const = 0;

	/**
	 * Get a formatted version string.
	 */
	virtual QString version() const = 0;

	/**
	 * Get a description about the plugin.
	 */
	virtual QString description() const = 0;



	/**
	 * Enables the plugin.
	 * Has no effect if the plugin is already enabled.
	 * If the plugin is disabled, enables the plugin (and unpauses it, if necessary) and then returns immediately.
	 */
	virtual void enable();

	/**
	 * Pauses the plugin.
	 * Has no effect if the plugin is disabled.
	 */
	virtual void pause();

	/**
	 * Unpauses the plugin.
	 * Has no effect if the plugin is not paused.
	 */
	virtual void unpause();

	/**
	 * Disable the plugin.
	 * Has no effect if the plugin is already disabled.
	 * If the plugin is enabled, sets a flag and then return immediately.
	 */
	virtual void disable();



	/**
	 * Test if the plugin is enabled or not.
	 */
	bool enabled() const;

	/**
	 * Test if the plugin is paused or not.
	 * If the plugin is disabled, it is not paused.
	 */
	bool paused() const;

	/**
	 * Test if the plugin is disabled or not.
	 */
	bool disabled() const;



	/**
	 * Adds another exception to the number of exceptions, thrown
	 * by this plugin.
	 */
	void addException();

	/**
	 * @returns the number of exceptions thrown by this plugin
	 */
	std::size_t numExceptions() const;
};
///////////////////////////////////////////////////////////////////////////////////////////////////
